<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>山东营销风云榜</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../css/part/tabHead.css">
    <link rel="stylesheet" href="../../../css/part/mini.css">
</head>

<body>

<div id="app">
    <div id="tableHead">
        <img src="../../../img/part/sz/newAdd/saleDeptNewAdd.png" id="saleDeptHead" align="center">
        <a href="../../portal/navigationYX.html"><img src="../../../img/portal/min.png" id="miniImg"></a>
        <table width="100%">
            <tr >
                <thead>
                <th width="6%">NO</th>
                <th width="14%">机构</th>
                <th width="16%">当月新增上岗</th>
                <th width="17%">在册人力</th>
                <th width="17%">主管人力</th>
                <th width="15%">主管新增数</th>
                <th width="15%">主管新增率</th>
                </thead>
            </tr>
        </table>
    </div>
    <div id="midDiv"></div>
    <div class="tableBody">
        <table id="tab" width="100%">
            <tbody id="tbody">
            </tbody>
        </table>
    </div>
</div>
</body>
<script src="../../../js/vue.js"></script>
<script src="../../../js/axios.js"></script>
<script src="../../../js/head.js"></script>
<script src="../../../js/jquery-3.2.1.min.js"></script>
<script src="../../../js/share.js"></script>

<script>
    window.onload = function () {
        new Vue({
            el: '#app',
            data() {
                return {
                    //中支名称
                    saleDeptsName: '',
                    //当月新增上岗
                    saleDeptNewAgent: 0,
                    //在册人力
                    saleDeptAllAgent: 0,
                    //主管人力
                    saleDeptChargeNum: 0,
                    //主管新增数
                    saleDeptChargeIncrease: 0,
                    //主管新增率
                    saleDeptChargeYield: 0,
                    pojo: {},
                    divHeight: 0,

                }
            },
            created() {
                this.getSaleDeptNewAdd();
            },
            methods: {

                //获取各中支的数据
                getSaleDeptNewAdd() {
                    document.getElementById("midDiv").style.height = window.getComputedStyle(document.getElementById("tableHead")).getPropertyValue("height");
                    setTimeout(() => {
                        axios.get(`/newAdd/getSaleDeptNewAdd`).then(response => {
                            this.pojo = response.data;
                            var str = "";//定义用于拼接的字符串
                            var j = 0;
                            for (var i = 0; i < this.pojo.length; i++) {
                                if (this.pojo[i].saleDeptsName.includes("收展")){

                                    j=j+1;

                                    this.saleDeptNewAgent = this.saleDeptNewAgent + this.pojo[i].saleDeptNewAgent;
                                    this.saleDeptAllAgent = this.saleDeptAllAgent + this.pojo[i].saleDeptAllAgent;
                                    this.saleDeptChargeNum = this.saleDeptChargeNum + this.pojo[i].saleDeptChargeNum;
                                    this.saleDeptChargeIncrease = this.saleDeptChargeIncrease + this.pojo[i].saleDeptChargeIncrease;
                                    
                                    //拼接表格的行和列
                                    str = "<tr><td width=\"6%\">" + (j + 0) + "</td><td width=\"14%\">" + this.pojo[i].saleDeptsName + "</td><td width=\"16%\">" + this.pojo[i].saleDeptNewAgent + "</td><td width=\"17%\">" + this.pojo[i].saleDeptAllAgent + "</td><td width=\"17%\">" + this.pojo[i].saleDeptChargeNum + "</td><td width=\"15%\">" + this.pojo[i].saleDeptChargeIncrease + "</td><td width=\"15%\">" + this.dataHandle(this.pojo[i].saleDeptChargeYield) + "</td></tr>";
                                    //追加到table中
                                    $("#tbody").append(str);
                                }
                            }

                            str = "<tr><th colspan=\"2\" style=\"font-weight: bolder\">" + '合计:' + "</th>" +
                                "<th width=\"16%\">" + this.saleDeptNewAgent + "</th>" +
                                "<th width=\"17%\">" + this.saleDeptAllAgent + "</th>" +
                                "<th width=\"17%\">" + this.saleDeptChargeNum + "</th>" +
                                "<th width=\"15%\">" + this.saleDeptChargeIncrease + "</th>" +
                                "<th width=\"15%\">" + this.dataHandle(this.doubleHandle(this.saleDeptChargeIncrease, this.saleDeptChargeNum)) + "</th></tr>";
                            $("#tbody").append(str);
                        })
                    }, 200)

                },
                //数据处理
                dataHandle(_this) {
                    var data = _this + "";
                    if (data.indexOf(".") != -1) {
                        return data + '%'
                    }
                    if (data == -9999) {
                        return '-'
                    }
                    return data + ".0" + '%';
                },
                //处理两数相除
                doubleHandle(a, b) {
                    if (b == 0) {
                        return -9999;
                    } else {
                        return Math.round(a * 1000 / b) / 10;
                    }
                }

            }
        })
    }
</script>

</html>